package canvas;


import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

import objetos.CanvasGame;
import objetos.GamePanel;
import objetos.myCanvas;

public class CanvasMenuOpcoes extends myCanvas{

	public static CanvasMenuOpcoes instance = null;

	BufferedImage menuImage;
	BufferedImage easyOn;
	BufferedImage mediumOn;
	BufferedImage hardOn;
	BufferedImage menugameOn;
	BufferedImage botaoVoltarImg;
	BufferedImage botaoVoltarOnImg;
	
	BufferedImage checkOn;


	boolean voltarOn;
	
	long timerCompra, timerVenda;

	boolean ckeckSom = false;

	boolean ckeckResolucao = false;

	Random rnd = new Random();

	long diftime, timerCLick;

	public CanvasMenuOpcoes(){
		
		menuImage = GamePanel.loadImage("./../bgBack.png");   // imagem de fundo arvores
		menugameOn = GamePanel.loadImage("./../Opcoes.png");
		
		botaoVoltarImg = GamePanel.loadImage("./../botaoVoltar.png");
		
		botaoVoltarOnImg = GamePanel.loadImage("./../botaoVoltarOn.png");
		
		checkOn = GamePanel.loadImage("./../checkOn.png");
		
		instance = this;		
	
	}

	@Override
	public void SimulaSe(long diftime) {
		this.diftime = diftime;
		//System.out.print("\n MAPA ATUAL DO SHOP => " + CanvasGame.MapaAtual+ "\n");
		timerCLick += this.diftime;
		checaMouseLoja();
	}

	private void checaMouseLoja() {


		//dbg.drawRect(216, 225, 22, 22);  // som
		if(CanvasGame.instance.MouseX > 216 && CanvasGame.instance.MouseX < 238 && CanvasGame.instance.MouseY > 225 && CanvasGame.instance.MouseY < 247){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;
				
				if(ckeckSom == false){
					ckeckSom = true;
				}else{
					ckeckSom = false;
				}
			}
			
		}

		
		//dbg.drawRect(216, 250, 22, 22);  // resolucao
		if(CanvasGame.instance.MouseX > 216 && CanvasGame.instance.MouseX < 238 && CanvasGame.instance.MouseY > 250 && CanvasGame.instance.MouseY < 272){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;

				
				if(ckeckResolucao == false){
					ckeckResolucao = true;
				}else{
					ckeckResolucao = false;
				}
				
			}
			
		}
		
		
		
		 // voltar
		if(CanvasGame.instance.MouseX > 227 && CanvasGame.instance.MouseX < 392 && CanvasGame.instance.MouseY > 373 && CanvasGame.instance.MouseY < 408){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;

				if (CanvasMenuSelectDificuldade.instance == null) {
					CanvasMenuPrincipal2 menuPrincipal2 = new CanvasMenuPrincipal2();

				}
				GamePanel.canvasAtivo = CanvasMenuPrincipal2.instance;
			}
			
			voltarOn = true;
		}else{
			voltarOn = false;
		}






	}

	public void DesenhaSe(Graphics2D dbg) {


		dbg.drawImage(menuImage, 0, 0, null); // tamanho da imagem


		dbg.drawImage(menugameOn, GamePanel.WIDTH/2+328/2, GamePanel.PHEIGHT/2-194/2, null); // tamanho da imagem
		
		
		dbg.drawImage(botaoVoltarImg, GamePanel.WIDTH/2+440/2, GamePanel.PHEIGHT/2+254/2, null); // tamanho da imagem

		
		

		dbg.setColor(Color.RED);
		
		
		//molde
		//dbg.drawRect(216, 225, 22, 22);  // som
		
		if(ckeckSom == true){
			dbg.drawImage(checkOn, 216, 225, null);  // som
			
		}
		
		if(voltarOn == true){
			dbg.drawImage(botaoVoltarOnImg,GamePanel.WIDTH/2+440/2, GamePanel.PHEIGHT/2+254/2, null);  // som
			
		}
		
		
		
		//molde
		//dbg.drawRect(216, 250, 22, 22);  // resolucao
		
		if(ckeckResolucao == true){
			dbg.drawImage(checkOn, 216, 250, null);  // som
			
		}
	


	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();


		//CanvasGame.instance.dinheiro = 0;

		//CanvasGame.instance.listadePetdoveiculo.clear();
		//CanvasGame.instance.listadePetSystem.clear();

		//if (keyCode == KeyEvent.VK_ENTER) {
		//	GamePanel.canvasAtivo = CanvasGame.instance;	
		//}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		//System.out.print("MOVEU O MOUSEEEEEEEEEEEEE ");


	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//System.out.print("Clicou AEEEEEEEEEEEEEEH ");
		CanvasGame.instance.MouseX = e.getX();
		CanvasGame.instance.MouseY = e.getY();
		int cont = 0;

	}

	public static BufferedImage loadImage(String source) {
		BufferedImage image = null;
		try {
			BufferedImage tmp = ImageIO.read(CanvasGame.instance.getClass()
					.getResource(source));
			image = new BufferedImage(tmp.getWidth(), tmp.getHeight(),
					BufferedImage.TYPE_INT_ARGB);
			image.getGraphics().drawImage(tmp, 0, 0, null);
			tmp = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.print("CLICOU NO MOUSE AEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEH");

	}



}
